﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Base64
{
	public partial class ListItem : UserControl, IListItem
	{
		public ListItem()
		{
			InitializeComponent();

			this.Size = new Size(this.Width, lblTitle.Height + lblContent.Height);
			lblContent.MouseEnter += new EventHandler(Label_MouseEnter);
			lblTitle.MouseEnter += new EventHandler(Label_MouseEnter);
			lblContent.MouseLeave += new EventHandler(Label_MouseLeave);
			lblTitle.MouseLeave += new EventHandler(Label_MouseLeave);

			lblContent.Click += new EventHandler(Label_Click);
			lblTitle.Click += new EventHandler(Label_Click);

			lblContent.VisibleChanged += new EventHandler(lblContent_VisibleChanged);

		}

		void Label_Click(object sender, EventArgs e)
		{
			OnClick(e);
		}

		void lblContent_VisibleChanged(object sender, EventArgs e)
		{
			this.Height = lblTitle.Height + (lblContent.Visible ? lblContent.Height : 0);
		}

		public ListItem(string title, string content)
			: this()
		{
			this.Title = title;
			this.Content = content;
		}

		void Label_MouseEnter(object sender, EventArgs e)
		{
			OnMouseEnter(e);
		}

		void Label_MouseLeave(object sender, EventArgs e)
		{
			OnMouseLeave(e);
		}

		public virtual string Title
		{
			get
			{
				return lblTitle.Text;
			}
			set
			{
				lblTitle.Text = value;
			}
		}

		public virtual string Content
		{
			get
			{
				return lblContent.Text;
			}
			set
			{
				lblContent.Text = value;
				lblContent.Visible = value != "";
			}
		}

		protected override void OnMouseEnter(EventArgs e)
		{
			base.OnMouseEnter(e);
			this.BackColor = System.Drawing.SystemColors.Highlight;
			this.ForeColor = System.Drawing.SystemColors.HighlightText;
		}

		protected override void OnMouseLeave(EventArgs e)
		{
			base.OnMouseLeave(e);
			this.BackColor = System.Drawing.SystemColors.Control;
			this.ForeColor = System.Drawing.SystemColors.ControlText;
		}
	}
}
